package com.dap.dao.model;

import com.dap.utils.DBUtils;

import java.io.Serializable;


/**
 * 排序对象
 * 
 * @author WUDUFENG
 * 
 */
public class Order implements Serializable {
    private static final long serialVersionUID = -9052322409478952879L;

    // 排序方式
    public enum OrderType {
        ASC,
        DESC
    }


    /** 升序 */
    public static Order asc(String propertyName) {
        return new Order(propertyName, OrderType.ASC);
    }


    /**
     * 降序
     * 
     * @param propertyName
     * @return
     */
    public static Order desc(String propertyName) {
        return new Order(propertyName, OrderType.DESC);
    }

    /** 表字段名 */
    private String columnName;

    /** asc | desc **/
    private String sort;


    public Order() {}

    private Order(String propertyName, OrderType orderType) {
        this.columnName = propertyName;
        this.sort = " " + orderType.name();
    }


    public String getColumnName() {
        return columnName;
    }
    public void setColumnName(String columnName) {
        if (!DBUtils.checkName(columnName))
            throw new RuntimeException();

        this.columnName = columnName;
    }

    public String getSort() {
        return sort;
    }
    public void setSort(String sort) {
        this.sort = sort;
    }
}
